package com.wangyadong.hobby.concurrent;

import com.wangyadong.hobby.thread.ReentrantLock;

import static com.wangyadong.hobby.concurrent.CountDownLatchDemo.PRINT_CONSUMER;

public class ReentrantLockDemo {
    private static final ReentrantLock lock = new ReentrantLock();
    private static int shareData = 0;

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                try {
                    lock.lock();
                    shareData++;
                    PRINT_CONSUMER.accept("----------------------------" + shareData);
                } finally {
                    lock.unlock();
                }
            }).start();
        }
    }
}
